<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Управление пользователями</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
</head>
<body>
<f:view>
    <jsp:include page="menu.jsp"/>
    <jsp:include page="status.jsp"/>

    <h:form>
    <!-- Паджинатор -->
    <h:panelGroup layout="block">
        <h:panelGroup id="pager">

            <h:inputHidden value="#{UsersBean.page}"/>

            <h:outputText value="Страница: #{UsersBean.page}" styleClass="b"/>

            <a4j:commandLink action="#{UsersBean.toBegin}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/left3.png"/>
            </a4j:commandLink>
            <a4j:commandLink action="#{UsersBean.longPrevPage}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/left2.png"/>
            </a4j:commandLink>
            <a4j:commandLink action="#{UsersBean.prevPage}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/left.png"/>
            </a4j:commandLink>


            <h:panelGroup id="pager_nums">
                <a4j:repeat value="#{UsersBean.pageIndexes}" var="pageIndex">
                    <a4j:commandLink action="#{UsersBean.applyPage}" value="#{pageIndex.num}" styleClass="pager_page" reRender="tblUsers,pager">
                        <a4j:actionparam name="page_id" assignTo="#{UsersBean.page}" value="#{pageIndex.num}"/>
                    </a4j:commandLink>
                </a4j:repeat>
            </h:panelGroup>

            <a4j:commandLink action="#{UsersBean.nextPage}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/right.png"/>
            </a4j:commandLink>
            <a4j:commandLink action="#{UsersBean.longNextPage}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/right2.png"/>
            </a4j:commandLink>
            <a4j:commandLink action="#{UsersBean.toEnd}" ajaxSingle="true" reRender="tblUsers,pager" styleClass="pager_arr">
                <h:graphicImage value="/resources/img/arrows/right3.png"/>
            </a4j:commandLink>

            <h:outputText value="(всего: #{UsersBean.pagesCount})"/>
        </h:panelGroup>
        <!-- ---------- -->

        <rich:spacer width="10"/>

        <!-- Фильтр -->

        <h:outputText value="Фильтр: " styleClass="b"/>

        <h:outputText value="ФИО"/>
        <h:inputText value="#{SessionBean.usersFilter.fio}" styleClass="f_tb_l"/>

        <h:outputText value="Роль"/>
        <h:selectOneMenu value="#{SessionBean.usersFilter.roleId}" styleClass="f_s">
            <f:selectItems value="#{UsersBean.rolesAsSelectItems}"/>
        </h:selectOneMenu>

        <h:outputText value="Логин"/>
        <h:inputText value="#{SessionBean.usersFilter.login}" styleClass="f_tb_l"/>

        <h:outputText value="Начальник"/>
        <h:selectOneMenu value="#{SessionBean.usersFilter.parentManagerId}" styleClass="f_s">
            <f:selectItems value="#{UsersBean.managersAsSelectItems}"/>
        </h:selectOneMenu>

        <h:outputText value="Email"/>
        <h:inputText value="#{SessionBean.usersFilter.email}" styleClass="f_tb_l"/>

        <a4j:commandButton reRender="tblUsers,pager" value="Применить" action="#{UsersBean.applyFilter}">
            <a4j:actionparam name="user_id" assignTo="#{SessionBean.usersFilter.id}" value="-1"/>
            <a4j:actionparam name="user_client_id" assignTo="#{SessionBean.usersFilter.clientId}" value="-1"/>
        </a4j:commandButton>
        <!-- ------ -->

    </h:panelGroup>

    <rich:dataTable value="#{UsersBean.users}" var="user" id="tblUsers" styleClass="full" cellpadding="0" cellspacing="0"
            columnClasses="clm_actions,clm_white,clm_grey,clm_grey,clm_grey_b,clm_white,clm_white,clm_white,clm_white">
        <f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Пользователи"/>
                <rich:spacer width="10"/>
                <a4j:commandLink action="#" ajaxSingle="true" oncomplete="#{rich:component('createUserPanel')}.show()" id="bAddUser">
                    <a4j:actionparam name="user_id" assignTo="#{UsersBean.userId}" value="#{-1}"/>
                    <a4j:actionparam name="role_id" assignTo="#{sessionScope['selectedUserRoleId']}" value="#{-1}"/>
                    <h:graphicImage value="/resources/img/add_16.png"/>
                    <h:outputText value="Добавить" styleClass="fwhite"/>
                </a4j:commandLink>
                <rich:toolTip for="bAddUser" value="Добавить нового пользователя" style="color:black;font-weight:normal"/>
            </h:panelGroup>
        </f:facet>
        <rich:column>

            <%-- Действия --%>
            <%--<h:panelGroup rendered="#{user.id != 1}">--%>
            <h:panelGroup rendered="#{user.id != 1}">

                <%-- Редактировать пользователя --%>
                <a4j:commandLink ajaxSingle="true" id="editlink" action="#" oncomplete="#{rich:component('editUserPanel')}.show()" rendered="#{!user.isClient}">
                    <h:graphicImage value="resources/img/edit.gif"/>
                    <a4j:actionparam name="user_id" assignTo="#{UsersBean.userId}" value="#{user.id}"/>
                    <a4j:actionparam name="role_id" assignTo="#{sessionScope['selectedUserRoleId']}" value="#{user.userRoleId}"/>
                </a4j:commandLink>
                <rich:toolTip for="editlink" value="Редактировать данные пользователя"/>

                <%-- Удалить пользователя --%>
                <a4j:commandLink ajaxSingle="true" id="deletelink" action="#" oncomplete="#{rich:component('removeUserPanel')}.show()">
                    <h:graphicImage value="resources/img/delete.gif"/>
                    <a4j:actionparam name="user_id" assignTo="#{UsersBean.userId}" value="#{user.id}"/>
                    <a4j:actionparam name="page" assignTo="#{UsersBean.page}" value="#{UsersBean.page}"/>
                </a4j:commandLink>
                <rich:toolTip for="deletelink" value="Удалить пользователя"/>

                <%-- Сгенерировать новый пароль --%>
                <a4j:commandLink ajaxSingle="true" id="password" action="#" oncomplete="#{rich:component('sendUserPasswordPanel')}.show()">
                    <h:graphicImage value="/resources/img/send_16.png"/>
                    <a4j:actionparam name="user_id" assignTo="#{UsersBean.userId}" value="#{user.id}"/>
                </a4j:commandLink>
                <rich:toolTip for="password" value="Сгенерировать новый пароль и выслать его на почтовый ящик пользователя"/>

            </h:panelGroup>
        </rich:column>

        <rich:column style="width:1%;whitespace:nowrap">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Табельный"/><br>
                    <h:outputText value="номер"/>
                </h:panelGroup>
            </f:facet>
            <h:outputText value="#{user.num}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="ФИО / Клиент"/>
            </f:facet>

            <h:panelGroup rendered="#{!user.isClient}">
                <h:outputText value="#{user.fio}" id="fio"/>
            </h:panelGroup>
            <h:panelGroup rendered="#{user.isClient}">
                <a4j:commandLink action="#" oncomplete="document.location='ClientsPage.jsf'">
                    <a4j:actionparam name="client_name" assignTo="#{SessionBean.clientsFilter.name}" value="#{user.client.companyName}"/>
                    <a4j:actionparam name="client_group_id" assignTo="#{SessionBean.clientsFilter.clientGroupId}" value="-1"/>
                    <a4j:actionparam name="manager_id" assignTo="#{SessionBean.clientsFilter.managerId}" value="-1"/>
                    <h:outputText value="#{user.client.companyName}"/>
                </a4j:commandLink>
            </h:panelGroup>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Роль"/>
            </f:facet>
            <h:outputText value="#{user.role.name}"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Логин"/>
            </f:facet>
            <h:outputText value="#{user.login}" id="login"/>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:outputText value="Начальник"/>
            </f:facet>
            <h:outputText value="#{user.parentManger.fio}"/>
        </rich:column>

        <rich:column style="text-align:right">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Почтовый"/><br>
                    <h:outputText value="ящик"/>
                </h:panelGroup>
            </f:facet>
            <a4j:commandLink rendered="#{not user.isClient}" 
                             value="#{user.email}"
                             ajaxSingle="true"
                             action="#"
                             oncomplete="#{rich:component('userMailPanel')}.show()">
                <a4j:actionparam name="mail" assignTo="#{UsersBean.userMail}" value="#{user.email}"/>
            </a4j:commandLink>
            <a4j:commandLink rendered="#{user.isClient}"
                             value="#{user.client.contactEmail}"
                             ajaxSingle="true"
                             action="#"
                             oncomplete="#{rich:component('userMailPanel')}.show()">
                <a4j:actionparam name="mail" assignTo="#{UsersBean.userMail}" value="#{user.client.contactEmail}"/>
            </a4j:commandLink>
        </rich:column>

        <rich:column>
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Дата"/><br>
                    <h:outputText value="создания"/>
                </h:panelGroup>
            </f:facet>
            <h:outputText value="#{user.creationDate}"/>
        </rich:column>

    </rich:dataTable>
</h:form>

<rich:modalPanel id="editUserPanel" autosized="true" width="700">
    <f:facet name="header">
        <h:outputText value="Введите данные о пользователе"/>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('editUserPanel')}.hide();return false;"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">
        <h:form>

            <h:inputHidden value="#{UsersBean.userId}"/>
            <h:inputHidden value="#{UsersBean.user.id}"/>

            <jsp:include page="messages.jsp"/>

            <h:panelGroup id="dvCreateHeader" styleClass="" layout="block" style="background-color:whitesmoke;">
                <h:panelGroup rendered="#{!UsersBean.isUserRoleIdSelected}">
                    <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright">
                        <h:outputText value="Роль" styleClass="b"/>
                        <h:panelGroup>
                            <h:selectOneMenu value="#{UsersBean.selectedUserRoleId}">
                                <f:selectItems value="#{UsersBean.rolesAsSelectItems}"/>
                            </h:selectOneMenu>
                            <a4j:commandLink action="#" reRender="dvCreateFields,dvCreateHeader">
                                <h:graphicImage value="/resources/img/apply1.png"/>
                            </a4j:commandLink>
                        </h:panelGroup>
                    </h:panelGrid>
                </h:panelGroup>
                <h:panelGroup rendered="#{UsersBean.isUserRoleIdSelected}">
                    <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright">
                        <h:outputText value="Роль" styleClass="b" style="font-size:120%"/>
                        <h:outputText value="#{UsersBean.selectedUserRoleString}" style="font-size:120%"/>
                    </h:panelGrid>
                </h:panelGroup>
            </h:panelGroup>

            <h:panelGroup id="dvCreateFields" style="margin-top:15px" styleClass="" layout="block">
                <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright" rendered="#{UsersBean.isUserRoleIdSelected}">

                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="ФИО"/><br>
                        <h:outputText styleClass="hint" value="Например: Иванов Алексей Петрович"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.fio}" rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <h:panelGroup>
                        <h:outputText value="Логин"/><br>
                        <h:outputText styleClass="hint" value="Например: ivanov (только маленькие латинские буквы и цифры)"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.login}"/>

                    <h:panelGroup rendered="#{UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Клиент"/><br>
                        <h:outputText styleClass="hint" value="Выберите клиента, связанного с данным пользователем"/>
                    </h:panelGroup>
                    <h:selectOneMenu value="#{UsersBean.user.clientId}" rendered="#{UsersBean.selectedUserRoleIsClient}">
                        <f:selectItems value="#{ClientsBean.clientsAsSelectItems}"/>
                    </h:selectOneMenu>

                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Табельный номер"/><br>
                        <h:outputText styleClass="hint" value="Например: А145"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.num}" rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Почтовый ящик"/><br>
                        <h:outputText styleClass="hint" value="Например: ivanov@goodfil.ru"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.email}"
                                 rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <h:outputText value="Начальник" rendered="#{UsersBean.selectedUserRoleIsManager}"/>
                    <h:selectOneMenu value="#{UsersBean.user.parentManagerId}" id="addUserParentManagerId" rendered="#{UsersBean.selectedUserRoleIsManager}">
                        <f:selectItems value="#{UsersBean.managersAsSelectItems}"/>
                    </h:selectOneMenu>

                </h:panelGrid>
            </h:panelGroup>

            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">
                <a4j:commandButton value="Сохранить"
                                   action="#{UsersBean.saveUser}"
                                   styleClass="btnsz"
                                   reRender="tblUsers,pager"
                                   oncomplete="if (#{!UsersBean.hasFacesErrors}) #{rich:component('editUserPanel')}.hide();"/>
                <a4j:commandButton value="Отменить"
                                   styleClass="btnsz"
                                   onclick="#{rich:component('editUserPanel')}.hide();return false;"/>

            </h:panelGrid>
        </h:form>
    </a4j:outputPanel>
</rich:modalPanel>

<rich:modalPanel id="createUserPanel" autosized="true" width="700">
    <f:facet name="header">
        <h:outputText value="Введите данные о пользователе"/>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('createUserPanel')}.hide();return false;"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">
        <h:form>

            <h:inputHidden value="#{UsersBean.userId}"/>
            <h:inputHidden value="#{UsersBean.user.id}"/>

            <jsp:include page="messages.jsp"/>

            <h:panelGroup id="dvCreateHeader" styleClass="" layout="block" style="background-color:whitesmoke;">
                <h:panelGroup rendered="#{!UsersBean.isUserRoleIdSelected}">
                    <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright">
                        <h:outputText value="Роль" styleClass="b"/>
                        <h:panelGroup>
                            <h:selectOneMenu value="#{UsersBean.selectedUserRoleId}">
                                <f:selectItems value="#{UsersBean.rolesAsSelectItems}"/>
                            </h:selectOneMenu>
                            <a4j:commandLink action="#" reRender="dvCreateFields,dvCreateHeader">
                                <h:graphicImage value="/resources/img/apply1.png"/>
                            </a4j:commandLink>
                        </h:panelGroup>
                    </h:panelGrid>
                </h:panelGroup>
                <h:panelGroup rendered="#{UsersBean.isUserRoleIdSelected}">
                    <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright">
                        <h:outputText value="Роль" styleClass="b" style="font-size:120%"/>
                        <h:outputText value="#{UsersBean.selectedUserRoleString}" style="font-size:120%"/>
                    </h:panelGrid>
                </h:panelGroup>
            </h:panelGroup>

            <h:panelGroup id="dvCreateFields" style="margin-top:15px" styleClass="" layout="block">
                <h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright" rendered="#{UsersBean.isUserRoleIdSelected}">

                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="ФИО"/><br>
                        <h:outputText styleClass="hint" value="Например: Иванов Алексей Петрович"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.fio}" rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <h:panelGroup>
                        <h:outputText value="Логин"/><br>
                        <h:outputText styleClass="hint" value="Например: ivanov (только маленькие латинские буквы и цифры)"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.login}"/>

                    <h:panelGroup rendered="#{UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Клиент"/><br>
                        <h:outputText styleClass="hint" value="Выберите клиента, связанного с данным пользователем"/>
                    </h:panelGroup>
                    <h:selectOneMenu value="#{UsersBean.user.clientId}" rendered="#{UsersBean.selectedUserRoleIsClient}">
                        <f:selectItems value="#{ClientsBean.clientsWithoutUsersAsSelectItems}"/>
                    </h:selectOneMenu>

                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Табельный номер"/><br>
                        <h:outputText styleClass="hint" value="Например: А145"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.num}" rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <%--<h:panelGroup>--%>
                        <%--<h:outputText value="Почтовый ящик"/><br>--%>
                        <%--<h:outputText styleClass="hint" value="Например: ivanov@goodfil.ru"/>--%>
                    <%--</h:panelGroup>--%>
                    <%--<h:inputText value="#{UsersBean.user.email}"/>--%>
                    <h:panelGroup rendered="#{!UsersBean.selectedUserRoleIsClient}">
                        <h:outputText value="Почтовый ящик"/><br>
                        <h:outputText styleClass="hint" value="Например: ivanov@goodfil.ru"/>
                    </h:panelGroup>
                    <h:inputText value="#{UsersBean.user.email}"
                                 rendered="#{!UsersBean.selectedUserRoleIsClient}"/>

                    <h:outputText value="Начальник" rendered="#{UsersBean.selectedUserRoleIsManager}"/>
                    <h:selectOneMenu value="#{UsersBean.user.parentManagerId}" id="addUserParentManagerId" rendered="#{UsersBean.selectedUserRoleIsManager}">
                        <f:selectItems value="#{UsersBean.managersAsSelectItems}"/>
                    </h:selectOneMenu>

                </h:panelGrid>
            </h:panelGroup>
            
            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">
                <a4j:commandButton value="Сохранить"
                                   action="#{UsersBean.saveUser}"
                                   styleClass="btnsz"
                                   reRender="tblUsers,pager"
                                   oncomplete="if (#{!UsersBean.hasFacesErrors}) #{rich:component('createUserPanel')}.hide();"/>
                <a4j:commandButton value="Отменить"
                                   styleClass="btnsz"
                                   onclick="#{rich:component('createUserPanel')}.hide();return false;"/>

            </h:panelGrid>
        </h:form>
    </a4j:outputPanel>
</rich:modalPanel>

<%--<rich:modalPanel id="userPanel" autosized="true" width="650">--%>
    <%--<f:facet name="header">--%>
        <%--<h:outputText value="Введите данные о пользователе"/>--%>
    <%--</f:facet>--%>
    <%--<f:facet name="controls">--%>
        <%--<h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('userPanel')}.hide();return false;"/>--%>
    <%--</f:facet>--%>
    <%--<h:form>--%>
        <%--<a4j:outputPanel ajaxRendered="true">--%>

            <%--<h:inputHidden value="#{UsersBean.userId}"/>--%>
            <%--<h:inputHidden value="#{UsersBean.user.id}"/>--%>

            <%--<jsp:include page="messages.jsp"/>--%>

            <%--<h:panelGrid columns="2" styleClass="full" cellspacing="0" cellpadding="0" columnClasses="dleft,dright">--%>

                <%--<h:outputText value="ФИО*"/>--%>
                <%--<h:inputText value="#{UsersBean.user.fio}"--%>
                             <%--required="true" requiredMessage="Поле ФИО не заполнено"/>--%>

                <%--<h:outputText value="Роль*"/>--%>
                <%--<h:selectOneMenu value="#{UsersBean.user.userRoleId}"--%>
                                 <%--required="true" requiredMessage="Не указана роль пользователя">--%>
                    <%--<f:selectItems value="#{UsersBean.rolesAsSelectItems}"/>--%>
                <%--</h:selectOneMenu>--%>

                <%--<h:outputText value="Логин*"/>--%>
                <%--<h:inputText value="#{UsersBean.user.login}"--%>
                             <%--required="true" requiredMessage="Не указан логин пользователя"/>--%>

                <%--<h:outputText value="Клиент***"/>--%>
                <%--<h:selectOneMenu value="#{UsersBean.user.clientId}">--%>
                    <%--<f:selectItems value="#{ClientsBean.clientsAsSelectItems}"/>--%>
                <%--</h:selectOneMenu>--%>

                <%--<h:outputText value="Табельный номер"/>--%>
                <%--<h:inputText value="#{UsersBean.user.num}"/>--%>

                <%--<h:outputText value="Почтовый ящик*"/>--%>
                <%--<h:inputText value="#{UsersBean.user.email}"--%>
                             <%--required="true" requiredMessage="Не указан почтовй адрес пользователя"/>--%>

                <%--<h:outputText value="Начальник**"/>--%>
                <%--<h:selectOneMenu value="#{UsersBean.user.parentManagerId}" id="addUserParentManagerId">--%>
                    <%--<f:selectItems value="#{UsersBean.managersAsSelectItems}"/>--%>
                <%--</h:selectOneMenu>--%>

                <%--<h:outputText value="Максимальный размер скидки (%)**"/>--%>
                <%--<h:inputText value="#{UsersBean.user.maxDiscountPercent}"--%>
                             <%--converterMessage="Максимальный размер скидки в процентах должен быть числом">--%>
                    <%--<f:convertNumber maxFractionDigits="2" type="number"/>--%>
                <%--</h:inputText>--%>

                <%--<h:outputText value="Максимальный размер скидки (рубли)**"/>--%>
                <%--<h:inputText value="#{UsersBean.user.maxDiscountPercent}"--%>
                             <%--converterMessage="Максимальный размер скидки в рублях должен быть числом">--%>
                    <%--<f:convertNumber maxFractionDigits="2" type="number"/>--%>
                <%--</h:inputText>--%>

            <%--</h:panelGrid>--%>
        <%--</a4j:outputPanel>--%>

        <%--<h:panelGrid columns="1" styleClass="full" cellspacing="0" cellpadding="0" style="padding:5px;">--%>
            <%--<h:outputText value="* Эти поля обязательны для заполнения" styleClass="comment"/>--%>
            <%--<h:outputText value="** Эти поля обязательны для заполнения для пользователей с ролью \"Менеджер\"" styleClass="comment"/>--%>
            <%--<h:outputText value="*** Эти поля обязательны для заполнения для пользователей с ролью \"Клиент\"" styleClass="comment"/>--%>
        <%--</h:panelGrid>--%>

        <%--<h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">--%>
            <%--<a4j:commandButton value="Сохранить"--%>
                               <%--action="#{UsersBean.saveUser}"--%>
                               <%--styleClass="btnsz"--%>
                               <%--reRender="tblUsers,pager" --%>
                               <%--oncomplete="if (#{!UsersBean.hasFacesErrors}) #{rich:component('userPanel')}.hide();"/>--%>
            <%--<a4j:commandButton value="Отменить"--%>
                               <%--styleClass="btnsz"--%>
                               <%--onclick="#{rich:component('userPanel')}.hide();return false;"/>--%>

        <%--</h:panelGrid>--%>
    <%--</h:form>--%>
<%--</rich:modalPanel>--%>

<rich:modalPanel id="removeUserPanel" autosized="true" width="300">
    <f:facet name="header">
        <h:outputText value="Внимание!"/>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('removeUserPanel')}.hide();return false;"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">
        <h:form>
            <h:inputHidden value="#{UsersBean.user.id}"/>
            <h:inputHidden value="#{UsersBean.userId}"/>

            <jsp:include page="messages.jsp"/>

            <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                <h:graphicImage value="/resources/img/warning_32.png"/>
                <h:outputText value="Удалить пользователя \"#{UsersBean.user.fio}\"?"/>
            </h:panelGrid>

            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">
                <a4j:commandButton value="Да"
                                   action="#{UsersBean.removeUser}"
                                   reRender="tblUsers,pager"
                                   styleClass="btnsz"
                                   oncomplete="if(#{!UsersBean.hasFacesErrors}) #{rich:component('removeUserPanel')}.hide();"/>
                <a4j:commandButton value="Нет"
                                   styleClass="btnsz"
                                   onclick="#{rich:component('removeUserPanel')}.hide();return false;"/>
            </h:panelGrid>
        </h:form>
    </a4j:outputPanel>
</rich:modalPanel>

<rich:modalPanel id="sendUserPasswordPanel" autosized="true" width="300">
    <f:facet name="header">
        <h:outputText value="Генерация пароля"/>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('sendUserPasswordPanel')}.hide();return false;"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">
        <h:form>
            <h:inputHidden value="#{UsersBean.user.id}"/>
            <h:inputHidden value="#{UsersBean.userId}"/>

            <h:outputText value="Сгенерировать пароль для пользователя \"#{UsersBean.user.fio}\"?" rendered="#{!UsersBean.user.isClient}"/>
            <h:outputText value="Сгенерировать пароль для клиента \"#{UsersBean.user.client.companyName}\"?" rendered="#{UsersBean.user.isClient}"/>
            <br/>
            <h:selectBooleanCheckbox value="#{UsersBean.sendByEmail}"/>
            <h:outputText value="Отправить пароль на почтовый ящик"/>

            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">
                <a4j:commandButton value="Да"
                                   action="#{UsersBean.sendPassword}"
                                   styleClass="btnsz"
                                   oncomplete="if(#{!UsersBean.hasFacesErrors}) #{rich:component('sendUserPasswordPanel')}.hide();"/>
                <a4j:commandButton value="Нет"
                                   styleClass="btnsz"
                                   onclick="#{rich:component('sendUserPasswordPanel')}.hide();return false;"/>
            </h:panelGrid>

        </h:form>
    </a4j:outputPanel>
</rich:modalPanel>

<rich:modalPanel id="userMailPanel" autosized="true" width="550">
    <f:facet name="header">
        <h:outputText value="Отправить письмо"/>
    </f:facet>
    <f:facet name="controls">
        <h:graphicImage value="resources/img/close.png" styleClass="hidelink" onclick="#{rich:component('userMailPanel')}.hide();return false;"/>
    </f:facet>
    <a4j:outputPanel ajaxRendered="true">
        <h:form>
            <h:inputHidden value="#{UsersBean.userMail}"/>

            <jsp:include page="messages.jsp"/>

            <h:panelGroup layout="block" style="background-color:whitesmoke;">
                <h:outputText value="Отправка письма на ящик: "/>
                <h:outputText value="#{UsersBean.userMail}" styleClass="b"/>
            </h:panelGroup>

            <h:panelGroup layout="block" style="margin-top:15px;">
                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" columnClasses="dleft top,dright top">
                    <h:outputText value="Текст"/>
                    <rich:editor width="500" height="150" id="edit" viewMode="source" value="#{UsersBean.userMailText}"/>
                </h:panelGrid>
            </h:panelGroup>

            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight" cellspacing="0" cellpadding="0">
                <a4j:commandButton value="Отправить"
                                   action="#{UsersBean.sendTextMail}"
                                   styleClass="btnsz"
                                   oncomplete="if(#{!UsersBean.hasFacesErrors}) #{rich:component('userMailPanel')}.hide();"/>
                <a4j:commandButton value="Отмена"
                                   styleClass="btnsz"
                                   onclick="#{rich:component('userMailPanel')}.hide();return false;"/>
            </h:panelGrid>

        </h:form>
    </a4j:outputPanel>
</rich:modalPanel>

</f:view>
</body>
</html>
